﻿<script src="~/admui-13945148017-1592211513218/public/vendor/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/bootstrap-datepicker/bootstrap-datepicker.zh-CN.min.js"></script>
<link href="~/admui-13945148017-1592211513218/public/css/examples/tables/datatable.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap4.css" rel="stylesheet" />
<link href="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/font-awesome/4.6.0/css/font-awesome.min.css">
<link href="~/tree.css" rel="stylesheet" />
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap.min.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-bootstrap/dataTables.bootstrap4.js"></script>
<script src="~/admui-13945148017-1592211513218/public/vendor/datatables-responsive/dataTables.responsive.min.js"></script>
<script src="~/GoTRI/js/main.js"></script>
<script src="~/admui-13945148017-1592211513218/public/js/tsk/sweetalert.min.js"></script>
<script src="~/comboTreePlugin.js"></script>

<form id="form1" runat="server">
    <div class="page-container" id="admui-pageContent">
        <div class="page animation-fade page-forms">
            <div class="page-header" style="margin-top:70px">
                <h1 class="page-title" id="biao1">添加月报</h1>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                        <a class="icon wb-home" href="javascript:;">月报管理</a>
                    </li>
                    <li class="breadcrumb-item active" id="biao2">添加月报</li>
                </ol>
                <label style="display:none" id="lbl_Id"></label>
            </div>
            <div class="page-content">
                <div class="panel">
                    <div class="panel-body container-fluid">
                        <div class="card-body">
                            <div class="col-lg-6 col-md-6">
                                <label id="jieshouhuibao" style="margin-bottom:10px;">汇报给</label>
                                <div id="quanbu" hidden="hidden">
                                    <input id="qiangnihuibaoren" hidden="hidden" style="width:100%;margin-bottom:15px" disabled="disabled"><br />
                                    <label id="huibaoshijian" hidden="hidden">汇报时间</label><br />
                                    <input id="huibaoshiantianxie" hidden="hidden" style="width:100%;margin-bottom:15px" disabled="disabled">
                                </div>

                                <div id="xianshihuibaoren" class="select-tree-wrap" style="width:100%"></div>
                                @*<select class="form-control" style="margin-bottom:15px" id="xianshihuibaoren">
                                    </select>*@
                            </div>
                            <div class="col-lg-6 col-md-6">
                                <label>本月工作</label>
                                <textarea id="TextArea1" rows="5" cols="50" class="form-control"></textarea>
                            </div>
                            <div class="col-lg-6 col-md-6">
                                <label style="margin-top:10px;">下月计划</label>
                                <textarea id="TextArea2" rows="5" cols="50" class="form-control"></textarea>
                            </div>
                            <div class="col-lg-6 col-md-6">
                                <label>其他事项</label>
                                <textarea id="TextArea3" rows="5" cols="50" class="form-control"></textarea>
                            </div>
                        </div>
                        <div style="text-align: center;width:100%">
                            <button class="btn btn-success float-right" id="tijiao" onclick="tijiao()" style="width:100%; margin-bottom:70px;">提交</button>
                            <button class="btn btn-success float-right" hidden="hidden" id="yuedu" onclick="ydugangneng()" style="width:100%; margin-bottom:70px;">阅读</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<input type="text" hidden="hidden" id="idzhi" />
<script type="text/javascript" language="javascript" class="init">
    $(document).ready(function () {
        var shu = getQuery("id");
        var benren = getQuery("benren");
        $("#idzhi").val(shu);
        if (shu != null && shu != "0") {
            $('#xianshihuibaoren').attr('hidden', "hidden");
            $('#tijiao').attr('hidden', "hidden");
            $('#TextArea1').attr('disabled', "true");
            $('#TextArea2').attr('disabled', "true");
            $('#TextArea3').attr('disabled', "true");

            $('#quanbu').removeAttr("hidden");
            $('#qiangnihuibaoren').removeAttr("hidden");
            $('#jieshouhuibao').text("发送人");
            $('#huibaoshijian').removeAttr("hidden");
            $('#huibaoshiantianxie').removeAttr("hidden");
            //$('#a').removeAttr("hidden");

            if (benren == "1" && benren != null) {
                $('#a').removeAttr("href");
                $('#a').attr('href', "BenRenHuiBaoList");
            } else {
                $('#yuedu').removeAttr("hidden");
                $('#a').removeAttr("href");
                $('#a').attr('href', "HuiBaoList");
            }
            huibaoxinxi(shu);
        } else {
            huibaoren();
            //$('#a').attr('hidden', "hidden");
        }
    });

    function ydugangneng() {
        $("#yuedu").attr("disabled", "disabled");
        var id = $("#idzhi").val();
        $.ajax({
            type: 'post',
            url: '../HuiBao/upHuiBaoList',
            dataType: 'text',
            async: true,
            data: { id: id },
            success: function (result) {
                $("#yuedu").attr("disabled", "block");
                if (result == "1") {
                    swal("已读成功 （该数据将不会在显示）!", "操作成功!", "success");
                    location.href = "../PhoneHuiBao/HuiBaoList";
                } else {
                    swal("已读失败!", "操作出现异常!", "error");
                }
            }
        });
    }

    function huibaoxinxi(id) {
        $.ajax({
            type: 'post',
            url: '../PhoneHuiBao/xianshihuibaoxinxi',
            async: false,
            dataType: 'json',
            data: { id: id },
            success: function (date) {
                $(date).each(function (key) {
                    $('#qiangnihuibaoren').val(date[key].huiBaoRen);
                    $('#TextArea1').val(date[key].ben);
                    $('#TextArea2').val(date[key].xia);
                    $('#TextArea3').val(date[key].qita);
                    $('#huibaoshiantianxie').val(date[key].shijian);
                })
            },
        })
    }

    function huibaoren() {

        $.ajax({
            type: 'post',
            url: '../HuiBao/GetHuiBaoRen',
            async: false,
            dataType: 'json',
            success: function (date) {
                if (date != null && date != "") {
                    var SampleJSONData = date;
                    let bbb = $('#xianshihuibaoren').comboTree({
                        source: SampleJSONData,
                        isMultiple: true,
                        isFirstClassSelectable: false, //第一级是否可选
                        cascadeSelect: true,
                        selectedlength: 100 //最多可选
                    });
                } else {
                    var ddl = $("#xianshihuibaoren");
                    ddl.append("<option value='0'>请给该员工添加岗位</option>");
                }
            },
        })
    }

    function tijiao() {
        var shuju = $('.select-menu-input').attr('data-id');
        var dangqian = $("#TextArea1").val();
        var xia = $("#TextArea2").val();
        var qita = $("#TextArea3").val();
        var zhuangtai = "月报";
        var huibaorenid = shuju;
        if (dangqian == null && dangqian == "") {
            swal("本日工作不能为空!", "操作出现异常!", "error");
        } else if (xia == null && xia == "") {
            swal("明日计划不能为空!", "操作出现异常!", "error");
        } else if (qita == null && qita == "") {
            swal("其他计划不能为空!", "操作出现异常!", "error");
        } else if (huibaorenid == "" && huibaorenid != null) {
            swal("汇报人不能为空!", "操作出现异常!", "error");
        } else {
            $("#tijiao").attr("disabled", "disabled");
            $.ajax({
                type: 'post',
                url: '../HuiBao/GetHuiAdd',
                async: false,
                dataType: 'text',
                data: { dangqian: dangqian, xia: xia, qita: qita, zhuangtai: zhuangtai, huibaorenid: huibaorenid },
                success: function (result) {
                    $("#tijiao").attr("disabled", "block");
                    if (result == "1") {
                        swal("添加成功 （该数据将不会在显示）!", "操作成功!", "success");
                        location.href = "../PhoneHuiBao/BenRenHuiBaoList";
                    } else {
                        swal("添加失败!", "操作出现异常!", "error");
                    }
                },
            })
        }
    }

    function getQuery(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURI(r[2]); return null;
    }

</script>
